package com.iafme.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iafme.dto.req.CollegesReqDTO;
import com.iafme.dto.res.CollegesResDTO;
import com.iafme.model.Colleges;
import com.iafme.model.Enterprise;
import com.iafme.service.CollegesService;
import com.systemframework.annotation.OperateAnnotation;
import com.systemframework.common.BaseCommonInterface;
import com.systemframework.enums.BusinessType;
import com.systemframework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/20 14:39
 */
@RestController
@RequestMapping("/colleges")
@AllArgsConstructor
public class CollegesController implements BaseCommonInterface<CollegesReqDTO, CollegesResDTO> {

    private final CollegesService collegesService;

    @OperateAnnotation(businessType = BusinessType.INSERT,name = "高校合作")
    @SaCheckPermission("partner:colleges:add")
    @Override
    public Result<String> save(@Valid CollegesReqDTO collegesReqDTO) {
        Colleges colleges = Convert.convert(Colleges.class, collegesReqDTO);
        collegesService.save(colleges);
        return Result.successResult();
    }

    @OperateAnnotation(businessType = BusinessType.UPDATE,name = "高校合作")
    @SaCheckPermission("partner:colleges:edit")
    @Override
    public Result<String> update(@Valid CollegesReqDTO collegesReqDTO) {
        Colleges colleges = Convert.convert(Colleges.class, collegesReqDTO);
        collegesService.updateById(colleges);
        return Result.successResult();
    }

    @OperateAnnotation(businessType = BusinessType.DELETE,name = "高校合作")
    @SaCheckPermission("partner:colleges:delete")
    @Override
    public Result<String> del(Integer id) {
        collegesService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<CollegesResDTO>> lists(CollegesReqDTO collegesReqDTO) {
        return Result.successResult(collegesService.lists(collegesReqDTO));
    }

    @Override
    public Result<CollegesResDTO> findById(Integer integer) {
        return null;
    }

    @OperateAnnotation(businessType = BusinessType.BATCHDELETE,name = "高校合作")
    @SaCheckPermission("partner:colleges:delete")
    @Override
    public Result<String> batchDel(List<CollegesResDTO> list) {
        List<Integer> ids = list.stream().map(CollegesResDTO::getId).collect(Collectors.toList());
        collegesService.removeByIds(ids);
        return Result.successResult();
    }
}
